home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BEERSRC.ZIP / STARS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-19  |  2.7 KB  |  151 lines

  1.  
  2. #include <stdio.h>
  3. #include <io.h>
  4. #include <fcntl.h>
  5. #include <sys\stat.h>
  6. #include <dos.h>
  7. #include <string.h>
  8.  
  9.  
  10. char palette[768];
  11.  
  12.  
  13. void loadpic(char *file)
  14. {
  15.    int      filvar;
  16.    char     data, count;
  17.    unsigned pos, i;
  18.  
  19.  
  20.    filvar = open(file, O_RDONLY | O_BINARY, S_IREAD);
  21.    lseek(filvar, -768, SEEK_END);
  22.    if (read(filvar, palette, 768) != 768) abort();
  23.    for (i = 0; i < 768; i++) {
  24.       palette[i] = (char) palette[i]>>2;
  25.    }
  26.  
  27.    lseek(filvar, 128, SEEK_SET);
  28.  
  29.    pos = 0;
  30.    while ((read(filvar, &count, 1) == 1) && (pos < 0xfa00)) {
  31.       if ((count & 0xc0) == 0xc0) {
  32.      count = count & 0x3f;
  33.      read(filvar, &data, 1);
  34.       } else {
  35.      data = count; count = 1;
  36.       }
  37.  
  38.       for (i = 0; i < count; i++) {
  39.      pokeb(0xa000, pos++, data);
  40.       }
  41.    }
  42.  
  43.    close(filvar);
  44.  
  45.  
  46. }
  47.  
  48.  
  49. void screenmode(int mode)
  50. {
  51.    struct REGPACK regs;
  52.  
  53.    regs.r_ax = mode;
  54.    intr(0x10, ®s);
  55.  
  56.    regs.r_ax = 0x0100;
  57.    regs.r_cx = 0x2000;
  58.    intr(0x10, ®s);
  59.  
  60. }
  61.  
  62. void setcolor(char *ptr)
  63. {
  64.    struct REGPACK regs;
  65.  
  66.    regs.r_ax = 0x1012;
  67.    regs.r_bx = 0;
  68.    regs.r_cx = 256;
  69.    regs.r_dx = (unsigned) ptr;
  70.    regs.r_es = _DS;
  71.    intr(0x10, ®s);
  72.  
  73. }
  74.  
  75. void setattrib(int m)
  76. {
  77.    struct REGPACK regs;
  78.  
  79.    regs.r_ax = 0x1013;
  80.    regs.r_bx = (m << 8);
  81.    intr(0x10, ®s);
  82.  
  83. }
  84.  
  85. struct starstrc {
  86.    int  x, y;
  87.    int  color;
  88.    int  speed;
  89. };
  90.  
  91.  
  92. struct starstrc star[500];
  93. int    n;
  94.  
  95.  
  96. void main(void)
  97. {
  98.    int    x, y, i;
  99.    char   infile[80];
  100.    char   outfile[80];
  101.  
  102.    printf("\n\nStarfield Definer [c] by ALPHA-HELIX.\n\n");
  103.    printf("StarMap [.PCX] : ");
  104.    fflush(stdin);
  105.    scanf("%s", infile);
  106.    strcat(infile, ".PCX");
  107.    printf("Output [.STA] : ");
  108.    fflush(stdin);
  109.    scanf("%s", outfile);
  110.    strcat(outfile, ".STA");
  111.  
  112.    screenmode(0x13);
  113.  
  114.    setattrib(1);
  115.  
  116.    loadpic(infile);
  117.    setcolor(palette);
  118.  
  119.    for (y = 0; y < 200; y++) {
  120.       for (x = 0; x < 320; x++) {
  121.      if ((i=peekb(0xa000, y*320 + x)) != 0) {
  122.         star[n].x = x;
  123.         star[n].y = y;
  124.         star[n].color = i;
  125.         switch (i) {
  126.            case 15: star[n].speed = 8; break;
  127.            case 14: star[n].speed = 7; break;
  128.            case 13: star[n].speed = 6; break;
  129.            case 12: star[n].speed = 5; break;
  130.            case 11: star[n].speed = 4; break;
  131.            case 10: star[n].speed = 3; break;
  132.            case 9: star[n].speed = 2; break;
  133.            case 7: star[n].speed = 1; break;
  134.          //  case 7: star[n].speed = 2; break;
  135.         }
  136.         n++;
  137.      }
  138.       }
  139.    }
  140.  
  141.    i = open(outfile, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, S_IWRITE);
  142.    write(i, &n, 2);
  143.    write(i, star, n*sizeof(struct starstrc));
  144.    close(i);
  145.  
  146.  
  147.    screenmode(0x02);
  148.  
  149.  
  150. }
  151.